<?php

namespace App\Repository\Repositories;

use App\Repository\Models\User;
use App\Repository\Repositories\Interfaces\UserRepository;

/**
 * Class UserRepositoryEloquent.
 *
 * @package namespace App\Repository\Repositories;
 */
class UserRepositoryEloquent extends BaseRepository implements UserRepository
{
    /**
     * 搜索
     * @var array
     */
    protected $fieldSearchable = [
        'created_at' => 'between',
        'personal_enterprise',
    ];

    public $fieldFuzzySearch = [
        'name',
        'phone',
    ];

    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return User::class;
    }

    public function checkUserLogin($username, $pwd)
    {
        $userinfo = $this->query()->where(function ($query) use ($username){$query->where('name',$username)->orWhere('phone','=',$username);})->where(['pwd'=>$pwd])->select('id','shop_id','name','pic','phone','email','identification_type','personal_enterprise','is_test_user','status')->first();

        $userinfo = $userinfo ? $userinfo->toArray(): '';

        return $userinfo;
    }

    public function checkPhone($phone)
    {
        $data = $this->query()->where('phone',$phone)->select('id','shop_id','name','pic','phone','email','identification_type','personal_enterprise','is_test_user','status')->first();

        $data = $data ? $data->toArray(): '';

        return $data;
    }


    public function checkUserName($user_name)
    {
        $data = $this->query()->where('name',$user_name)->select('id','shop_id','name','pic','phone','email','identification_type','personal_enterprise','is_test_user','status')->first();

        $data = $data ? $data->toArray(): '';

        return $data;
    }


    public function checkPayPwd($id,$pay_pwd){
        $data = $this->query()->where(['id'=>$id,'pay_pwd'=>md5($pay_pwd)])->select('id')->first();
       
        $data = $data ? $data->toArray():null;
      
        return $data;
    }
}
